//
//  ZMYinShiAnimationVC.m
//  testDemo
//
//  Created by 赵林瑞 on 16/5/15.
//  Copyright © 2016年 RZOL. All rights reserved.
//

#import "ZMYinShiAnimationVC.h"

@interface ZMYinShiAnimationVC ()

@property (nonatomic, weak) CALayer *layer;

@end

@implementation ZMYinShiAnimationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    CALayer *layer = [CALayer layer];
    
    // 位置
    layer.position = CGPointMake(100, 300);
    
    // 设置尺寸
    layer.bounds = CGRectMake(0, 0, 29, 130);
    
    // 颜色
//    layer.backgroundColor = [UIColor redColor].CGColor;
    
    layer.contents = (id)[UIImage imageNamed:@"zhizhen"].CGImage;
    
    [self.view.layer addSublayer:layer];
    
    _layer = layer;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint position = [touch locationInView:self.view];
    
    NSLog(@"(x: %f , y: %f)", position.x, position.y);
    
    
    // 开启事务
    //    [CATransaction begin];
    
    // 取消隐世动画
    //    [CATransaction setDisableActions:YES];
    //    _layer.position = CGPointMake(100, 100);
    
    // 设置边框
    _layer.borderWidth = arc4random_uniform(5) + 1;
    CGFloat r = arc4random_uniform(256) / 255.0;
    CGFloat g = arc4random_uniform(256) / 255.0;
    CGFloat b = arc4random_uniform(256) / 255.0;
    //    _layer.borderColor = [UIColor colorWithRed:r green:g blue:b alpha:1].CGColor;
    
    // 设置背景颜色
    _layer.backgroundColor = [UIColor colorWithRed:r green:g blue:b alpha:1].CGColor;
    
    // 设置圆角半径
    _layer.cornerRadius = arc4random_uniform(50);
    
    // 设置位置
    _layer.position = position;
    
    // 提交事务
    //    [CATransaction commit];
}

@end
